package com.example.broadcastrecevicedemo;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

public class MyReceiver extends BroadcastReceiver {
    private static final String TAG ="tag" ;

    /**
     * 接受广播后的回调方法，用于处理接收到的广播
     * @param context
     * @param intent  广播消息对象
     */
    @Override
    public void onReceive(Context context, Intent intent) {
        String action=intent.getAction();
        switch (action){
            //接受指定的系统广播
            case Intent.ACTION_BOOT_COMPLETED:
                Toast.makeText(context,"开机启动完成!",Toast.LENGTH_SHORT).show();
                break;

            case "com.example.BroadcastRecevice.NORMAL":
                String text=intent.getStringExtra("extra_text");
                Log.d(TAG,"全局广播接收器收到："+text);
                break;
        }
    }

}